#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=100010;
int t;
int n,m,L,V,res1,res2;
int d[N],v[N],a[N],p[N];
bool cmp(PII &a,PII &b)
{
    return a.y<b.y;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d%d",&n,&m,&L,&V);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&d[i],&v[i],&a[i]);
        }
        for(int i=1;i<=m;i++)
        {
            scanf("%d",&p[i]);
        }
        res1=res2=0;
        vector<PII> segs;
        for(int i=1;i<=n;i++)
        {
            if(a[i]==0)
            {
                if(d[i]<=p[m]&&v[i]>V)
                {
                    res1++;
                    int l=1,r=m;
                    while(l<r)
                    {
                        int mid=l+r>>1;
                        if(p[mid]>=d[i])
                        {
                            r=mid;
                        }
                        else
                        {
                            l=mid+1;
                        }
                    }
                    segs.push_back({l,m});
                    //cout<<i<<' ';
                }
            }
            else if(a[i]>0)
            {
                if(d[i]<=p[m]&&2*a[i]*(LL)(p[m]-d[i])+v[i]*v[i]>V*V)
                {
                    res1++;
                    int l=1,r=m;
                    while(l<r)
                    {
                        int mid=l+r>>1;
                        if(d[i]<=p[mid]&&2*a[i]*(LL)(p[mid]-d[i])+v[i]*v[i]>V*V)
                        {
                            r=mid;
                        }
                        else
                        {
                            l=mid+1;
                        }
                    }
                    //cout<<i<<' ';
                    segs.push_back({l,m});
                }
            }
            else
            {
                int l=1,r=m;
                while(l<r)
                {
                    int mid=l+r>>1;
                    if(p[mid]>=d[i])
                    {
                        r=mid;
                    }
                    else
                    {
                        l=mid+1;
                    }
                }
                if(d[i]<=p[l]&&2*a[i]*(LL)(p[l]-d[i])+v[i]*v[i]>V*V)
                {
                    res1++;
                    //cout<<i<<' ';
                    int x=l;
                    l=x,r=m;
                    while(l<r)
                    {
                        int mid=l+r+1>>1;
                        if(d[i]<=p[mid]&&2*a[i]*(LL)(p[mid]-d[i])+v[i]*v[i]>V*V)
                        {
                            l=mid;
                        }
                        else
                        {
                            r=mid-1;
                        }
                    }
                    segs.push_back({x,l});
                }
            }
        }
        sort(segs.begin(),segs.end(),cmp);
        int ed=-2e9;
        for(int i=0;i<segs.size();i++)
        {
            if(segs[i].x>ed)
            {
                ed=segs[i].y;
                res2++;
            }
        }
        printf("%d %d\n",res1,m-res2);
    }
    return 0;
}
